﻿using ConfExpert.Forms.Base;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid;
using DevTeam;
using System;

namespace ConfExpert.Forms.SatinAlma
{
    public partial class CheckPrices : XForm
    {
        public CheckPrices()
        {
            InitializeComponent();
        }

        private void CheckPrices_Load(object sender, EventArgs e)
        {
            gridView1.Init("CompareKumasFiyat");

            gridView1.MakeColumnInvisible("YuklemeLinesId", "KonfId");
            gridView1.FormatAsNumber(3, "kFiyat", "yFiyat");
            gridView1.FormatAsNumber(1, "YKOran");
            gridView1.Columns["kCurrencyId"].ColumnEdit = 
            gridView1.Columns["yCurrencyId"].ColumnEdit = RI(Rp.Currency);

            GridFormatRule gridFormatRule = new GridFormatRule();
            FormatConditionRuleDataBar formatConditionRuleDataBar = new FormatConditionRuleDataBar();
            gridFormatRule.Column = gridView1.Columns["YKOran"];
            formatConditionRuleDataBar.PredefinedName = "Yellow Gradient";
            gridFormatRule.Rule = formatConditionRuleDataBar;
            gridView1.FormatRules.Add(gridFormatRule);

            gridView1.SetCaptions("YKOran:YK %");
            gridView1.MakeReadOnly("kFiyat", "kCurrencyId", "yFiyat", "yCurrencyId");
            gridView1.AddSummary();
            gridView1.BestFitColumns();

            if (!ytk(255))
                btnKaydet.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;

            btnKaydet.ItemClick += btnKaydet_ItemClick;
        }

        void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            string xml = gridView1.SerializeChanges();
            ExecuteNonQuery("UpdKumasFiyat", xml);
        }
    }
}
